//
//  HttpRequestManager.h
//  WisdomZhuHai
//
//  Created by Admin on 13-9-12.
//  Copyright (c) 2013年 wyd. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ASIHTTPRequest.h"
#import "ASINetworkQueue.h"
#import "UIImageView+WebCache.h"

@protocol HttpRequestDelegate <NSObject>

- (void)requestDidFinish:(ASIHTTPRequest*)request;
- (void)requestDidFail:(ASIHTTPRequest*)request;

@optional
- (void)queueDidFinish:(ASINetworkQueue*)queue;
@end

@interface HttpRequestManager : NSObject

- (int)createHttpRequestQueue:(id<HttpRequestDelegate>)delegate;
- (BOOL)ifQueueUsable:(int)queueId;
- (BOOL)setSuspended:(BOOL)flag ForQueue:(int)queueId;
- (BOOL)removeHttpRequestQueue:(int)queueId;
- (void)removeAllHttpRequestQueue;

- (BOOL)addHttpRequestToQueue:(int)queueId Url:(NSURL*)url ToPath:(NSString*)path UserInfo:(NSDictionary*)dic Delegate:(id<HttpRequestDelegate>)delegate;//添加下载任务到队列中，UserInfo为自定义信息，可以在返回的ASIHTTPRequest中获得
- (BOOL)removeHttpRequestFromQueue:(int)queueId UserInfo                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           :(NSDictionary*)dic;//从队列中取消下载任务

- (void)startHttpDownloadTaskImmediately:(NSURL*)url ToPath:(NSString*)path withUserInfo:(NSDictionary*)dic Delegate:(id<HttpRequestDelegate>)delegate;//立即开始一个下载任务，不会加入到队列中，UserInfo为自定义信息，可以在返回的ASIHTTPRequest中获得
- (void)getHttpInfo:(NSURL*)url withUserInfo:(NSDictionary*)dic Delegate:(id<HttpRequestDelegate>)delegate;//获取http内容，UserInfo为自定义信息，可以在返回的ASIHTTPRequest中获得

//block版本
- (BOOL)addHttpRequestToQueue:(int)queueId Url:(NSURL*)url ToPath:(NSString*)path UserInfo:(NSDictionary*)dic success:(ASIRequestSuccessBlock)success failure:(ASIRequestFailureBlock)failure;//添加下载任务到队列中，UserInfo为自定义信息，可以在返回的ASIHTTPRequest中获得
- (void)startHttpDownloadTaskImmediately:(NSURL*)url ToPath:(NSString*)path withUserInfo:(NSDictionary*)dic success:(ASIRequestSuccessBlock)success failure:(ASIRequestFailureBlock)failure;//立即开始一个下载任务，不会加入到队列中，UserInfo为自定义信息，可以在返回的ASIHTTPRequest中获得
- (void)getHttpInfo:(NSURL*)url withUserInfo:(NSDictionary*)dic success:(ASIRequestSuccessBlock)success failure:(ASIRequestFailureBlock)failure;//获取http内容，UserInfo为自定义信息，可以在返回的ASIHTTPRequest中获得
- (void)getHttpInfo:(NSURL *)url postParams:(NSDictionary*)params success:(ASIRequestSuccessBlock)success failure:(ASIRequestFailureBlock)failure;

+ (NSString*)getCachePathByUrl:(NSURL*)url;
+ (void)ClearCache;
+ (HttpRequestManager*)getSharedInstance;

@end
